package cores

import (
	beego "github.com/beego/beego/v2/server/web"
	"net/http"
	"xpms/app/asset"
)

type ErrorController struct {
	beego.Controller
}

func (c *ErrorController) Error404() {
	//c.Data["json"] = Entity{
	//	Code: http.StatusNotFound,
	//	Msg:  "Not Found",
	//}
	//c.ServeJSON()
	c.Ctx.ResponseWriter.Header().Add("Content-Type", "text/html; charset=utf-8")
	//http.ServeFile(ctx.ResponseWriter, ctx.Request, "view/")
	bytes, err := asset.Asset("view/index.html") // 根据地址获取对应内容
	if err != nil {
		//fmt.Println("出现错误", err)
		return
	}
	str := string(bytes[:])
	c.Ctx.WriteString(str)
}
func (c *ErrorController) Error401() {
	c.Data["json"] = Entity{
		Code: http.StatusUnauthorized,
		Msg:  "Permission denied",
	}
	c.ServeJSON()
}
func (c *ErrorController) Error403() {
	c.Data["json"] = Entity{
		Code: http.StatusForbidden,
		Msg:  "Forbidden",
	}
	c.ServeJSON()
}
